package view.itemRenderes.mediators
{
	import events.library.EventSetLibraryItemProperty;
	import events.room.EventSetRoomProperty;
	
	import flash.events.Event;
	
	import model.ModelRooms;
	
	import mx.controls.Alert;
	
	import org.flashIso.engine.base.IsoRoom;
	import org.flashIso.engine.library.objects.LBase;
	import org.robotlegs.mvcs.Mediator;
	
	import view.itemRenderes.ItemRendererIsoRoom;
	import view.itemRenderes.ItemRendererLTile;
	
	public class MediatorItemRendererIsoRoom extends Mediator {
		[Inject]
		public var v:ItemRendererIsoRoom;
		
		[Inject]
		public var mr:ModelRooms;
		
		override public function onRegister() : void  {
			eventMap.mapListener(v, Event.CHANGE, labelChange, Event);
		}
		
		private function labelChange(e:Event) : void {
			trace("labelChange " + e.target);
			if (mr.getRoomById(v.textInput.text) != null){
				Alert.show("A room with this id already exists!","Rename Room");
			}else{
				dispatch(new EventSetRoomProperty(EventSetRoomProperty.CHANGE_PROPERTY, v.data as IsoRoom, "id", v.textInput.text));				
			}
		}
	}
}